<template>
  <div class="login-panel">
    <h2 class="title">后台管理系统</h2>
    <el-tabs type="border-card" class="demo-tabs" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><Coordinate /></el-icon>
            <span>账号登陆</span>
          </span>
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><Iphone /></el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <login-phone />
      </el-tab-pane>
    </el-tabs>
    <div class="password-related">
      <el-checkbox v-model="isKeepPassword" label="记住密码" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button class="submit" type="primary" @click="loginClicked">立即登录</el-button>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import { Coordinate, Iphone } from '@element-plus/icons-vue'
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'

export default defineComponent({
  components: {
    Coordinate,
    Iphone,
    LoginAccount,
    LoginPhone
  },
  setup() {
    const isKeepPassword = ref(true)
    // 组件实例类型，便于知道组件有什么属性和方法
    const accountRef = ref<InstanceType<typeof LoginAccount>>()
    const currentTab = ref('account')
    const loginClicked = () => {
      if (currentTab.value === 'account') {
        accountRef.value?.dealLoginClicked(isKeepPassword.value)
      } else {
        console.log('执行手机登录')
      }
    }
    return {
      isKeepPassword,
      accountRef,
      currentTab,
      loginClicked
    }
  }
})
</script>

<style scoped lang="less">
.login-panel {
  width: 320px;
  .title {
    text-align: center;
    margin-bottom: 15px;
  }
  .custom-tabs-label {
    .el-icon {
      vertical-align: middle;
      margin-right: 5px;
    }
  }
  .password-related {
    display: flex;
    justify-content: space-between;
    margin: 8px 0 12px 0;
  }
  .submit {
    width: 100%;
  }
}
</style>
